/**
 * 
 */
package org.vsg.stock.test;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Vector;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.vsg.common.configration.PropertiesSupport;
import org.vsg.stock.extension.service.StockAnalysisService;
import org.vsg.stock.extension.vo.AttentionBlock;
import org.vsg.stock.extension.vo.LinkageCateStockVO;


/**
 * @author vison
 *
 */
public class StkAttentionBlock {

	private final static Logger logger = LoggerFactory.getLogger(StkAttentionBlock.class);	
	
	static private DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	

	private String encoding;

	
	public void exec(ApplicationContext appContext) throws Exception {

		PropertiesSupport proSupport = (PropertiesSupport)appContext.getBean("propertyConfigurer");		
		

		String dir = proSupport.getProperties().getProperty("stock.linkage.dir");
		if (dir == null) {
			//logger.warn("Property 'stock.dailyline.dirk' is not defined! ");
			throw new Exception("Property 'stock.linkage.dir' is not defined!");
		}		
		
		StockAnalysisService stkAnalyService = (StockAnalysisService)appContext.getBean("stockAnalysisService");
		
		AttentionBlock ab1 = new AttentionBlock();
		ab1.setId("313");
		ab1.setDescription("上证龙头");
		ab1.setStartDate( sdf.parse("2010-03-27") );
		ab1.setType("板块");
		ab1.setCycle(20);
		
		AttentionBlock ab2 = new AttentionBlock();
		ab2.setId("319");
		ab2.setDescription("上证信息");
		ab2.setStartDate( sdf.parse("2010-03-27") );
		ab2.setType("板块");
		ab2.setCycle(20);

		AttentionBlock ab3 = new AttentionBlock();
		ab3.setId("889");
		ab3.setDescription("家电");
		ab3.setStartDate( sdf.parse("2010-03-27") );
		ab3.setType("板块");
		ab3.setCycle(20);
		
		List<AttentionBlock> abList = new Vector<AttentionBlock>();
		abList.add(ab1);
		abList.add(ab2);
		abList.add(ab3);
		
		
		List<LinkageCateStockVO> cstVoList = stkAnalyService.analyseStocksFromAttentionBlock(abList);
		
		for (LinkageCateStockVO vo : cstVoList) {
			System.out.println(vo.getStockName() + "#" + vo.getLastShownDate()+"#"+vo.getAssemblyCates());
			System.out.println(vo.getStockCode());
		}
		
	}
	
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub


				
		
		ClassLoader clsLoader = StkAttentionBlock.class.getClassLoader();
		// --- run the main page ---
		// build the read the path , dzh's home path
		String[] configContextFiles = {
				"classpath:/configurationContext.xml",
				"classpath*:/applicationContext.xml",
				"classpath*:/dataAccessContext.xml"
		};
		
		ApplicationContext ctx = new ClassPathXmlApplicationContext(configContextFiles,true);
		
	
		StkAttentionBlock mainProg = new StkAttentionBlock();
		
		try {
			mainProg.exec(ctx);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		logger.info("program run ... Ok!");
		



	}

}
